// pages/tabBar/my/component/upRecod/upRecod.js
import {request} from "../../../../../utils/util"
Page({

  /**
   * 页面的初始数据
   */
  data: {
      data:[],  //数据
      current:1,
      isLoading:true,  //加载动画
      fileNum:0,  //总文件数量
      fileSize:0,  //总文件大小
    },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    const that = this
    wx.setStorageSync('location', "user")
    this.getFileList();
    request("GET","/api/auth/user_log/")
    .then(res =>{
      if(res.statusCode === 200){
        if(res.data.data.length > 0){
          that.setData({
              fileNum:res.data.data[0].num || 0,
              fileSize:res.data.data[0].size || 0
          })
        }
      }
    })
  },
    /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    const that = this
    const param = {
    current:1
    }
    request("GET","/api/service/docinfo/?personal=personal",param)
    .then(res =>{
      if(res.statusCode === 200){
        that.setData({
          ...that.data,
          data:res.data.data.data,
          current:1
        })
        wx.stopPullDownRefresh()
      }
    })
     
    


  },
  /**
   * 上啦加载
   */
  onReachBottom:function () {
      const current = this.data.current + 1
      const that = this
      const param = {
        current
      }
      request("GET","/api/service/docinfo/?personal=personal",param,"",true)
      .then( res =>{
          if(res.statusCode === 200){
            let newList = JSON.stringify(res.data.data) === '{}' ? that.data.data : that.data.data.concat(res.data.data.data)
            let newCurrent = JSON.stringify(res.data.data) === '{}' ? current - 1 : current
            that.setData({
              ...that.data,
              data:newList,
              current:newCurrent
            })
          }
      })
  },
  /**
   * 获取数据的封装
   */
  getFileList(){
      const  that = this
      const param = {
        current:1
        // page_size:100
      }
      request("GET","/api/service/docinfo/?personal=personal",param,"",true)
      .then(res =>{
          if(res.statusCode === 200){
            that.setData({
              ...that.data,
              data:res.data.data.data,
              isLoading:false

            })
          }
      
      })
  }

})